<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="box">
        <h3>当前计数: {{counter}}</h3>
        <!-- <button v-on:click="counter--">-</button>
        <button v-on:click="counter++">+</button> -->
        <button v-on:click="sub">-</button>
        <button v-on:click="add">+</button>
    </div>
    <script>
        const app = new Vue({
            el: "#box",
            data: {
                counter: 0
            },
            methods: {
                add: function () {
                    this.counter++;
                    console.log("add被触发了");

                },
                sub: function () {
                    this.counter--;
                    console.log("sub被触发了");
                }
            }
        })
    </script>
</body>

</html>